/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mii.ejb.session;

import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import mii.dao.ComplainDAO;
import mii.dao.CustomerDAO;
import mii.dao.EngineerDAO;
import mii.dao.impl.ComplainDAOImpl;
import mii.dao.impl.CustomerDAOImpl;
import mii.dao.impl.EngineerDAOImpl;
import mii.ejb.entity.Complain;
import mii.ejb.entity.Customer;
import mii.ejb.entity.Engineer;

/**
 *
 * @author TEKNISI
 */
@Stateless
public class ComplainSessionBean implements ComplainSessionBeanLocal {
    @PersistenceContext(unitName = "helpdesk-ika-ejbPU")
    private EntityManager em;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public void saveComplain(String kodeComp, String jenisComp, String priorityComp, String statusComp, Date tglmasukComp, String isiComp, Customer customer, Engineer engineer) {
        EngineerDAO engdao = new EngineerDAOImpl(em);
        CustomerDAO custdao = new CustomerDAOImpl(em);
        ComplainDAO compdao = new ComplainDAOImpl(em);
        Complain comp = new Complain();
        comp.setKodeComp(kodeComp);
        comp.setJenisComp(jenisComp);
        comp.setPriorityComp(priorityComp);
        comp.setStatusComp(statusComp);
        comp.setTglmasukComp(new Date());
        comp.setIsiComp(isiComp);
        comp.setCustomer(customer);
        comp.setEngineer(engineer);
        try {
            compdao.insert(comp);
        } catch (Exception ex) {
            Logger.getLogger(ComplainSessionBean.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }
    
    @Override
    public List<Complain> getAllComplain() {
        ComplainDAO compdao = new ComplainDAOImpl(em);
        return compdao.getAll();
    }
        
    

}
